package cc.dullsky.tag;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;

import cc.dullsky.common.model.ArticleTag;
import cc.dullsky.common.model.Tag;

public class TagController extends Controller {
	/**
	 * 获取标签及标签的使用次数
	 */
	public void getTags() {
		List<Tag> tags = Tag.dao.findAll();
		List<Map<String, Object>> list = new ArrayList<>();
		for (Tag tag : tags) {
			Map<String, Object> map = new HashMap<>();
			map.put("id", tag.getId());
			map.put("name", tag.getName());
			map.put("count", ArticleTag.dao.countByTagId(tag.getId()));
			list.add(map);
		}
		renderJson(list);
	}
}
